<?php
class ui_tab_panel extends ui
{
	function __construct($parent=null)
	{
		$this->init(__FILE__,'div',array('class'=>'panel tab_panel'));
		$this->add(new ui_tab_bar());
		$this->active = (-1);
		$this->name = md5(rand(0,1000));
	}
	
	function add_tab($tab_title=null,$tab_body=null)
	{
		$new_tab = count($this->nodes[0]->nodes);
		$this->nodes[0]->add(new ui_tab());
		$this->nodes[0]->last->set('id','tab_'.$this->name.'_'.$new_tab);
		$this->nodes[0]->last->set('onclick','ti.tab(\''.$this->name.'\','.$new_tab.');');
		if(!is_null($tab_title))
		{
			if(is_string($tab_title))
			{
				$this->nodes[0]->last->text($tab_title);
			}
			else
			{
				$this->nodes[0]->last->add($tab_title);
			}
		}
		$this->tabs[] = $this->nodes[0]->last;
		$this->add(new ui_tab_body());
		$this->last->set('id','tabBody_'.$this->name.'_'.$new_tab);
		if(!is_null($tab_body))
		{
			$this->last->add($tab_body);
		}
		$this->panels[] = $this->last;
	}
	
	function pre_render($data)
	{
		parent::pre_render($data);
		if($this->active < 0)
		{
			$this->active=0;
		}
		$this->panels[$this->active]->set('class','tab_body_active',true);
		$this->tabs[$this->active]->set('class','tab_active',true);
	}
}
?>